﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Comod_Gifts : System.Web.UI.Page
{
    ZSql zs = new ZSql();
    Function f = new Function();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            initgvData();
            lblPath.Text = f.getModuleidAdd(Request["moduid"]);
        }
    }
    protected void btnSelec_Click(object sender, EventArgs e)
    {
        string sql = "select * from CS_Gifts where 1=1";
        if (!string.IsNullOrEmpty(txtselecName.Text))
        {
            sql += " and GiftsName='" + txtselecName.Text + "'";
        }
        PageNavigator1.Total = 1;
        PageNavigator1.Query = sql;
    }
    
    private void initgvData()
    {
        string sql = "select * from CS_Gifts";
        PageNavigator1.Total = 1;
        PageNavigator1.Query = sql;
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {

        Response.Redirect("GiftsAdd.aspx?moduid=" + Request["moduid"]+"&action=ad");
    }
    //protected void GvDataBand_RowDataBound(object sender, GridViewRowEventArgs e)
    //{
    //    if (e.Row.RowType == DataControlRowType.DataRow)
    //    {
    //        string AuditState = DataBinder.Eval(e.Row.DataItem, "IsOut").ToString();
    //        CheckBox ck = e.Row.Cells[6].FindControl("ckFlag") as CheckBox;
    //        if (AuditState == "1")
    //        {
    //            ck.Checked = true;

    //        }

    //    }
    //}
   
    protected void linkbtn_Click(object sender, EventArgs e)
    {
        string id = (sender as LinkButton).CommandArgument;
        Response.Redirect("GiftsAdd.aspx?moduid=" + Request["moduid"]+"&id="+id+"&action=add");
    }
    protected void linkbtnEdit_Click(object sender, EventArgs e)
    {
        string id = (sender as LinkButton).CommandArgument;
        Response.Redirect("GiftsAdd.aspx?moduid=" + Request["moduid"] + "&id=" + id + "&action=edit");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        int n = 0;
        if (this.GvData.Rows.Count > 0)
        {
            for (int i = 0; i < GvData.Rows.Count; i++)
            {
                CheckBox ck = GvData.Rows[i].Cells[6].FindControl("ckFlag") as CheckBox;
                if (ck.Checked)
                {
                    zs.Open("delete CS_Gifts  where giftsId=" + this.GvData.Rows[i].Cells[0].Text);
                    ClientScript.RegisterStartupScript(typeof(Page), "aa", "alert('删除成功');", true);
                }
                else
                {
                    n++;
                }

                if (n == this.GvData.Rows.Count)
                {

                    ClientScript.RegisterStartupScript(typeof(Page), "aa", "alert('至少应选择一项')", true);
                }


            }
        }
    }
}